package com.zld.smarket.controller;

import com.zld.smarket.pojo.GoodsType;
import com.zld.smarket.pojo.Storehouse;
import com.zld.smarket.pojo.Supplier;
import com.zld.smarket.result.ExceptionMsg;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.StorehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/storehouse")
public class StorehouseController {
    @Autowired
    private StorehouseService storehouseService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseData findList(Integer page, Integer limit) {
        return storehouseService.findList(page, limit);
    }

    @RequestMapping(value = "/del")
    public ResponseData delete(Long[] ids) {
        Integer integer = storehouseService.deleteById(ids);
        return new ResponseData(ExceptionMsg.SUCCESS);
    }

    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public ResponseData search(String s,Integer page, Integer limit){
        return  storehouseService.search(s,page, limit);
    }

    @RequestMapping(value = "/add")
    public ResponseData add(Storehouse storehouse) {
        Long i = storehouse.getStorehouseNo();
        if (storehouseService.selectbyno(i) > 0) {
            return new ResponseData(ExceptionMsg.ADDERROR);
        } else {
            Integer integer = storehouseService.addStorehouse(storehouse);
            return new ResponseData(ExceptionMsg.SUCCESS);
        }
    }
    @RequestMapping(value = "/update")
    public ResponseData updateById(Storehouse storehouse){
        return storehouseService.updateById(storehouse);
    }

    @RequestMapping("/getName")
    public List<Storehouse> getName() {
        return storehouseService.selectAll();
    }
}
